package com.io;

import com.hikvision.artemis.sdk.config.ArtemisConfig;
import com.io.properties.HKInfoProperties;
import com.io.util.GetCameraPreviewURL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import java.util.Map;

/**
 * The class/interface
 *
 * @author guodd
 * @version 1.0 use jdk 1.8
 */
@SpringBootApplication
@EnableConfigurationProperties
@RestController
public class AppRun {
    @Autowired
    private HKInfoProperties hkInfoProperties;

    public static void main(String[] args) {
        SpringApplication.run(AppRun.class, args);
    }

    @PostMapping(value = "/")
    public void index(@RequestBody Map<String, Object> params) {
        String viewURL = GetCameraPreviewURL.getViewURL(params);
        System.out.println(viewURL);
    }

    @PostConstruct
    public void init() {
        ArtemisConfig.host = hkInfoProperties.getHost();
        ArtemisConfig.appKey = hkInfoProperties.getAppKey();
        ArtemisConfig.appSecret = hkInfoProperties.getAppSecret();
    }
}
